﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

public partial class member_invoicequery : System.Web.UI.Page
{
	public string EnterpriseName = "";
    public string UserID = "";
    public string UserPower = "";
    public string Footer = "";
	
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Init.islogin(ref UserID,ref EnterpriseName,ref UserPower))
        {
            Response.Redirect("/Login.aspx");
        }        
        if (!UserPower.Contains("Manager"))
        {
            Response.Write("你没有权限！");
            Response.End();
        }
        this.EnableViewState = false;
        Response.Write(Init.InitDefault());
        DataSet ds = DataGroup();
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "djbh" };//主键
        GridView1.DataBind();   
    }

    private string mssqlConnect = ConfigurationManager.ConnectionStrings["DZFPmssqlConnect"].ToString();
    Common Init = new Common();
    MsSqlHelper mssql = new MsSqlHelper();

    //分页
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        DataSet ds=DataGroup();
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "djbh" };//主键
        int recordCount = ds.Tables[0].Rows.Count;
        GridView1.DataBind();
    }  

    //展示
    public DataSet DataGroup()
    {
        string ddh = dd.Text;
        string ckdh = ckd.Text;
        string dwmch = dwmc.Text;
        string startrq = srq.Text;
        string endrq = erq.Text;
        string sql = "select top 2000 rtrim(left(a.djbh,14)) as djbh,rtrim(ddh) as ddh,FP_DM,FP_HM,KPRQ,a.KPHJJE,PDF_URL,rtrim(a.wldwname) as company,rtrim(a.wldwid) as dwid "
                          + " from DZFPHZ a,DZFPSQHZ_LP b where replace(a.djbh,'HP-','')=b.djbh";
        if (!string.IsNullOrEmpty(ddh))
        {
            sql += " and a.ddh='"+ddh+"' ";
        }
        if (!string.IsNullOrEmpty(ckdh))
        {
            sql += " and left(a.djbh,14)='" + ckdh + "' ";
        }
        if (!string.IsNullOrEmpty(dwmch))
        {
            sql += " and a.wldwname like '%" + dwmch + "%' ";
        }
        if (!string.IsNullOrEmpty(startrq))
        {
            sql += " and a.kprq>='" + startrq + "' ";
        }
        if (!string.IsNullOrEmpty(endrq))
        {
            sql += " and a.kprq<='" + endrq + "' ";
        }
            sql += " order by a.KPRQ desc,a.djbh desc";
            if (Init.IsDebug)
            {
                ResultDeBug.Text = sql;
            }
        DataSet dss = mssql.ExecuteDs(sql,mssqlConnect);
        return dss;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = DataGroup();
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "djbh" };//主键
        int recordCount = ds.Tables[0].Rows.Count;
        GridView1.DataBind();
    }
}